/*
 * Copyright 2006 Mark Bakker <mark.bakker AT gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.gwtsvg.client;

/**
 *
 */
public class Coordinate {

  private static final String PIXEL_TYPE = "px";
  private static final String PERCENTAGE_TYPE = "%";

  private double x;
  private double y;

  private String unit = PIXEL_TYPE;

  private Coordinate() {
    super();
  }

  public Coordinate(Coordinate coordinate) {
    this(coordinate.x, coordinate.y, coordinate.unit);
  }

  public Coordinate(double x, double y, String unit) {
    super();
    if (unit.equalsIgnoreCase(PERCENTAGE_TYPE)) {
      this.unit = PERCENTAGE_TYPE;
    } else {
      this.unit = PIXEL_TYPE;
    }
    this.x = x;
    this.y = y;
  }

  public Coordinate(double x, double y) {
    this(x, y, PIXEL_TYPE);
  }

  public String getCoordinate() {
    return getCoordX() + " " + getCoordY();
  }

  public String getCoordX() {
    return "" + x;
  }

  public String getCoordY() {
    return "" + y;
  }

  public String getUnit() {
    return unit;
  }
}
